<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>历史记录</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta http-equiv="refresh" content="5">
		<link rel="stylesheet" href="../css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
				touch-action: none;
			}
			
			.title {
				padding: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
				background-color: #fff;
			}
			
			 .oa-contact-cell.mui-table .mui-table-cell {
				padding: 11px 0;
				vertical-align: middle;
			}
			
			.oa-contact-cell {
				position: relative;
				margin: -11px 0;
			}
				
			.oa-contact-avatar {
				width: 75px;
			}
			.oa-contact-avatar img {
				border-radius: 50%;
			}
			.oa-contact-content {
				width: 100%;
			}
			.oa-contact-name {
				margin-right: 20px;
			}
			.oa-contact-name, oa-contact-position {
				float: left;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" id="headerbf">
			<h1 class="mui-title">移动病房</h1>
		</header>
		<div class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<div class="title">
					选择监测对象查看血压、心率、脉搏、体温历史记录
				</div>
				<ul class="mui-table-view mui-table-view-striped mui-table-view-condensed" id="uiTableView">
					
				</ul>
				<div style="height:44px;"></div>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script>
			mui.init();
			mui.plusReady(function () {
			    var userIn = localStorage.getItem('userIn');
			    
			    if(userIn == '1'){
			    	listObserveUsers();
			    	checkHealth();
			    }
			    
			});
			
			function checkHealth(){
				var url = localStorage.getItem('remoteAddress') + '/api/checkHealth';
				var userName = localStorage.getItem('userName');
				mui.get(url,{
					userName: userName
					},function(data){
						var data = data.data;
						//alert(data.timeStep[0]);
						var isHealthy = data.isHealthy;
						//alert(isHealthy);
						if(isHealthy == '0'){
							healthAlarm();
						}
						//var tmp = new Array();
						//tmp = JSON.parse(localStorage.getItem('queryUserTimestep'));
						//alert(tmp[0]);
					},'json'
				);
			}
			
			function customQuery(queryUserName){
				localStorage.setItem('queryUserName', queryUserName);
				var customQueryPage = plus.webview.open('customQueryPage.html', 'customQueryPage', {}, 'slide-in-right', 200);
			}
			
			function healthAlarm(){
				plus.push.clear();
				plus.device.vibrate(1000);
				plus.push.createMessage("健康报警");
				alert("健康报警");
			}
			
			function listObserveUsers(){
				var url = localStorage.getItem('remoteAddress') + '/api/listObserveUsers';
				var userName = localStorage.getItem('userName');
				var observeUsersList = new Array();
				mui.get(url,{
					userName: userName,
					},function(data){
						var data = data.data;	
						observeUsersList = data.observeUsersList;
						var uiTableView = document.getElementById('uiTableView');
						for(var i = 0, len = observeUsersList.length; i < len; i++){
							let listUserName = observeUsersList[i].userName;
							var listUserGender = observeUsersList[i].gender;
							if(listUserGender == '1' || listUserGender == '男') {
								listUserGender = '男';
							}
							if(listUserGender == '0' ||listUserGender == '女') {
								listUserGender = '女';
							}
							var listUserTel = observeUsersList[i].userTel;
							//mui.toast(listUserName+listUserGender+listUserTel);
							var liTableViewCell = document.createElement('li');
							liTableViewCell.className = 'mui-table-view-cell';
							liTableViewCell.addEventListener('tap',function(){
								customQuery(listUserName);
							});
							var divSliderCell = document.createElement('div');
							divSliderCell.className = 'mui-slider-cell';
							var divContactCell = document.createElement('div');
							divContactCell.className = 'oa-contact-cell mui-table';
							var divContactAvatar = document.createElement('div');
							divContactAvatar.className = 'oa-contact-avatar mui-table-cell';
							var img = document.createElement('img');
							img.src = '../images/60x60.png';
							var divContactContent = document.createElement('div');
							divContactContent.className = 'oa-contact-content mui-table-cell';
							var divClearfix = document.createElement('div')
							divClearfix.className = 'mui-clearfix';
							var h4ContactName = document.createElement('h4');
							h4ContactName.className = 'oa-contact-name';
							h4ContactName.innerHTML = listUserName;
							var spanContactPosition = document.createElement('span');
							spanContactPosition.className = 'oa-contact-position mui-h6';
							spanContactPosition.innerHTML = listUserGender;
							var pContactEmail = document.createElement('p');
							pContactEmail.className = 'oa-contact-email mui-h6';
							pContactEmail.innerHTML = listUserTel;
							divClearfix.appendChild(h4ContactName);
							divClearfix.appendChild(spanContactPosition);
							divContactContent.appendChild(divClearfix);
							divContactContent.appendChild(pContactEmail);
							divContactAvatar.appendChild(img);
							divContactCell.appendChild(divContactAvatar);
							divContactCell.appendChild(divContactContent);
							divSliderCell.appendChild(divContactCell);
							liTableViewCell.appendChild(divSliderCell);
							uiTableView.appendChild(liTableViewCell);
						}
					},'json'
				);
			}
			
			var scrollContent = mui('.mui-scroll-wrapper');
			
			scrollContent.scroll({
				scrollY: true, //是否竖向滚动
				scrollX: false, //是否横向滚动
				bounce: false,//是否启用回弹
				startX: 0, //初始化时滚动至x
				startY: 0, //初始化时滚动至y
				indicators: false, //是否显示滚动条
				deceleration: 0.0006 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
			});
					
		</script>
	</body>

</html>